Example 1. Authorizing an application to access Twitter account data


In [15]:
import twitter

# XXX: Go to http://dev.twitter.com/apps/new to create an app and get values
# for these credentials, which you'll need to provide in place of these
# empty string values that are defined as placeholders.
# See https://dev.twitter.com/docs/auth/oauth for more information 
# on Twitter's OAuth implementation.

CONSUMER_KEY = ''
CONSUMER_SECRET =''
OAUTH_TOKEN = '-'
OAUTH_TOKEN_SECRET = ''

auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
                           CONSUMER_KEY, CONSUMER_SECRET)

twitter_api = twitter.Twitter(auth=auth)

# Nothing to see by displaying twitter_api except that it's now a
# defined variable

print twitter_api


<twitter.api.Twitter object at 0x7fb8102a1490>

In [16]:
# The Yahoo! Where On Earth ID for the entire world is 1.
# See https://dev.twitter.com/docs/api/1.1/get/trends/place and
# http://developer.yahoo.com/geo/geoplanet/

WORLD_WOE_ID = 1
US_WOE_ID = 23424977
RUS_WOE_ID = 2122265
# Prefix ID with the underscore for query string parameterization.
# Without the underscore, the twitter package appends the ID value
# to the URL itself as a special case keyword argument.

world_trends = twitter_api.trends.place(_id=WORLD_WOE_ID)
us_trends = twitter_api.trends.place(_id=US_WOE_ID)
rus_trends = twitter_api.trends.place(_id=RUS_WOE_ID)


print world_trends
print
print us_trends


[{u'created_at': u'2017-02-20T18:26:47Z', u'trends': [{u'url': u'http://twitter.com/search?q=%23PresidentsDay', u'query': u'%23PresidentsDay', u'tweet_volume': 254261, u'name': u'#PresidentsDay', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D8%A7%D9%84%D8%AA%D8%B9%D8%A7%D9%88%D9%86_%D9%84%D9%88%D9%83%D9%88%D9%85%D9%88%D8%AA%D9%8A%D9%81', u'query': u'%23%D8%A7%D9%84%D8%AA%D8%B9%D8%A7%D9%88%D9%86_%D9%84%D9%88%D9%83%D9%88%D9%85%D9%88%D8%AA%D9%8A%D9%81', u'tweet_volume': 71455, u'name': u'#\u0627\u0644\u062a\u0639\u0627\u0648\u0646_\u0644\u0648\u0643\u0648\u0645\u0648\u062a\u064a\u0641', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23NationalLoveYourPetDay', u'query': u'%23NationalLoveYourPetDay', u'tweet_volume': 26213, u'name': u'#NationalLoveYourPetDay', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23WatchLoveOnVevo', u'query': u'%23WatchLoveOnVevo', u'tweet_volume': 15678, u'name': u'#WatchLoveOnVevo', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23DiaInternacionalDelGato', u'query': u'%23DiaInternacionalDelGato', u'tweet_volume': 28526, u'name': u'#DiaInternacionalDelGato', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Steve+Hewlett%22', u'query': u'%22Steve+Hewlett%22', u'tweet_volume': None, u'name': u'Steve Hewlett', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Vitaly+Churkin%22', u'query': u'%22Vitaly+Churkin%22', u'tweet_volume': 18852, u'name': u'Vitaly Churkin', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Kurt+Cobain%22', u'query': u'%22Kurt+Cobain%22', u'tweet_volume': 85342, u'name': u'Kurt Cobain', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=Ally', u'query': u'Ally', u'tweet_volume': 66058, u'name': u'Ally', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=Colmenares', u'query': u'Colmenares', u'tweet_volume': 22768, u'name': u'Colmenares', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=CEDAE', u'query': u'CEDAE', u'tweet_volume': None, u'name': u'CEDAE', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22%ED%83%90%EB%9D%BC+%ED%8F%AC%EC%A7%80%EC%85%98%22', u'query': u'%22%ED%83%90%EB%9D%BC+%ED%8F%AC%EC%A7%80%EC%85%98%22', u'tweet_volume': None, u'name': u'\ud0d0\ub77c \ud3ec\uc9c0\uc158', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SophiaAbrah%C3%A3oNoV%C3%ADdeoShow', u'query': u'%23SophiaAbrah%C3%A3oNoV%C3%ADdeoShow', u'tweet_volume': 16066, u'name': u'#SophiaAbrah\xe3oNoV\xeddeoShow', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D8%A7%D9%88%D9%82%D9%81%D9%88%D8%A7_%D8%AD%D9%85%D8%A7%D9%82%D8%A7%D8%AA_%D9%87%D9%8A%D9%8A%D9%87_%D8%A7%D9%84%D8%AA%D8%B1%D9%81%D9%8A%D9%87', u'query': u'%23%D8%A7%D9%88%D9%82%D9%81%D9%88%D8%A7_%D8%AD%D9%85%D8%A7%D9%82%D8%A7%D8%AA_%D9%87%D9%8A%D9%8A%D9%87_%D8%A7%D9%84%D8%AA%D8%B1%D9%81%D9%8A%D9%87', u'tweet_volume': 19515, u'name': u'#\u0627\u0648\u0642\u0641\u0648\u0627_\u062d\u0645\u0627\u0642\u0627\u062a_\u0647\u064a\u064a\u0647_\u0627\u0644\u062a\u0631\u0641\u064a\u0647', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D8%A7%D9%84%D8%A8%D9%8A%D8%AA_%D8%A7%D9%84%D9%87%D9%84%D8%A7%D9%84%D9%8A_%D9%8A%D8%BA%D9%84%D9%8A', u'query': u'%23%D8%A7%D9%84%D8%A8%D9%8A%D8%AA_%D8%A7%D9%84%D9%87%D9%84%D8%A7%D9%84%D9%8A_%D9%8A%D8%BA%D9%84%D9%8A', u'tweet_volume': None, u'name': u'#\u0627\u0644\u0628\u064a\u062a_\u0627\u0644\u0647\u0644\u0627\u0644\u064a_\u064a\u063a\u0644\u064a', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23FelizLunes', u'query': u'%23FelizLunes', u'tweet_volume': 49998, u'name': u'#FelizLunes', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23VidalEnDDM', u'query': u'%23VidalEnDDM', u'tweet_volume': None, u'name': u'#VidalEnDDM', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23StrandedBae', u'query': u'%23StrandedBae', u'tweet_volume': 82936, u'name': u'#StrandedBae', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23LQvIU', u'query': u'%23LQvIU', u'tweet_volume': None, u'name': u'#LQvIU', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D0%BF%D1%83%D1%81%D1%82%D1%8C%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D1%8F%D1%82', u'query': u'%23%D0%BF%D1%83%D1%81%D1%82%D1%8C%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D1%8F%D1%82', u'tweet_volume': 11384, u'name': u'#\u043f\u0443\u0441\u0442\u044c\u0433\u043e\u0432\u043e\u0440\u044f\u0442', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23DontSleepOnSeokJin', u'query': u'%23DontSleepOnSeokJin', u'tweet_volume': 11858, u'name': u'#DontSleepOnSeokJin', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23DitesLeABaba', u'query': u'%23DitesLeABaba', u'tweet_volume': None, u'name': u'#DitesLeABaba', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23FamilyDay', u'query': u'%23FamilyDay', u'tweet_volume': 12008, u'name': u'#FamilyDay', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23HappyWendyDay', u'query': u'%23HappyWendyDay', u'tweet_volume': 97734, u'name': u'#HappyWendyDay', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23tagdelyoutuberJs', u'query': u'%23tagdelyoutuberJs', u'tweet_volume': None, u'name': u'#tagdelyoutuberJs', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23BTSBrokeBangtansRecordParty', u'query': u'%23BTSBrokeBangtansRecordParty', u'tweet_volume': 13178, u'name': u'#BTSBrokeBangtansRecordParty', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23EVETvatanaSahip%C3%87%C4%B1k%C4%B1yoruz', u'query': u'%23EVETvatanaSahip%C3%87%C4%B1k%C4%B1yoruz', u'tweet_volume': 19689, u'name': u'#EVETvatanaSahip\xc7\u0131k\u0131yoruz', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D9%85%D8%AD%D8%A7%D9%83%D9%85%D9%87_%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D8%B1%D8%AD%D9%85%D9%86_%D8%A7%D9%84%D9%85%D8%B7%D9%8A%D8%B1%D9%8A', u'query': u'%23%D9%85%D8%AD%D8%A7%D9%83%D9%85%D9%87_%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D8%B1%D8%AD%D9%85%D9%86_%D8%A7%D9%84%D9%85%D8%B7%D9%8A%D8%B1%D9%8A', u'tweet_volume': 17122, u'name': u'#\u0645\u062d\u0627\u0643\u0645\u0647_\u0639\u0628\u062f\u0627\u0644\u0631\u062d\u0645\u0646_\u0627\u0644\u0645\u0637\u064a\u0631\u064a', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%E3%81%93%E3%81%AE%E3%82%BF%E3%82%B0%E3%82%92%E8%A6%8B%E3%81%9F%E3%82%89%E6%80%96%E3%81%84%E3%82%82%E3%81%AE%E3%82%92%E3%81%B2%E3%81%A8%E3%81%A4%E3%81%82%E3%81%92%E3%82%8B', u'query': u'%23%E3%81%93%E3%81%AE%E3%82%BF%E3%82%B0%E3%82%92%E8%A6%8B%E3%81%9F%E3%82%89%E6%80%96%E3%81%84%E3%82%82%E3%81%AE%E3%82%92%E3%81%B2%E3%81%A8%E3%81%A4%E3%81%82%E3%81%92%E3%82%8B', u'tweet_volume': 11125, u'name': u'#\u3053\u306e\u30bf\u30b0\u3092\u898b\u305f\u3089\u6016\u3044\u3082\u306e\u3092\u3072\u3068\u3064\u3042\u3052\u308b', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D8%A7%D9%84%D8%A7%D9%87%D9%84%D9%8A_%D8%A7%D9%84%D8%A7%D8%B3%D8%AA%D9%82%D9%84%D8%A7%D9%84', u'query': u'%23%D8%A7%D9%84%D8%A7%D9%87%D9%84%D9%8A_%D8%A7%D9%84%D8%A7%D8%B3%D8%AA%D9%82%D9%84%D8%A7%D9%84', u'tweet_volume': None, u'name': u'#\u0627\u0644\u0627\u0647\u0644\u064a_\u0627\u0644\u0627\u0633\u062a\u0642\u0644\u0627\u0644', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23lagerhuis', u'query': u'%23lagerhuis', u'tweet_volume': None, u'name': u'#lagerhuis', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SiMiVidaFueraUnaPelicula', u'query': u'%23SiMiVidaFueraUnaPelicula', u'tweet_volume': None, u'name': u'#SiMiVidaFueraUnaPelicula', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23TheyHiredMeAnyway', u'query': u'%23TheyHiredMeAnyway', u'tweet_volume': None, u'name': u'#TheyHiredMeAnyway', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23VATANi%C3%A7inHAYIR', u'query': u'%23VATANi%C3%A7inHAYIR', u'tweet_volume': None, u'name': u'#VATANi\xe7inHAYIR', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%E3%81%84%E3%81%8B%E3%81%AE%E3%81%8A%E3%81%99%E3%81%97%E3%81%A7%E3%81%A9%E3%82%93%E3%81%AA%E4%BA%BA%E9%96%93%E3%81%8B%E3%83%90%E3%83%AC%E3%82%8B', u'query': u'%23%E3%81%84%E3%81%8B%E3%81%AE%E3%81%8A%E3%81%99%E3%81%97%E3%81%A7%E3%81%A9%E3%82%93%E3%81%AA%E4%BA%BA%E9%96%93%E3%81%8B%E3%83%90%E3%83%AC%E3%82%8B', u'tweet_volume': None, u'name': u'#\u3044\u304b\u306e\u304a\u3059\u3057\u3067\u3069\u3093\u306a\u4eba\u9593\u304b\u30d0\u30ec\u308b', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%2320FRevolucionZamorista', u'query': u'%2320FRevolucionZamorista', u'tweet_volume': 10931, u'name': u'#20FRevolucionZamorista', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SegundaDetremuraSDV', u'query': u'%23SegundaDetremuraSDV', u'tweet_volume': 14964, u'name': u'#SegundaDetremuraSDV', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23kimkazanacak', u'query': u'%23kimkazanacak', u'tweet_volume': 18866, u'name': u'#kimkazanacak', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SametBurakSar%C4%B1ya%C3%96zg%C3%BCrl%C3%BCk', u'query': u'%23SametBurakSar%C4%B1ya%C3%96zg%C3%BCrl%C3%BCk', u'tweet_volume': None, u'name': u'#SametBurakSar\u0131ya\xd6zg\xfcrl\xfck', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23stoptrump', u'query': u'%23stoptrump', u'tweet_volume': None, u'name': u'#stoptrump', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23Eurogroup', u'query': u'%23Eurogroup', u'tweet_volume': None, u'name': u'#Eurogroup', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23CosasQueEnamoran', u'query': u'%23CosasQueEnamoran', u'tweet_volume': None, u'name': u'#CosasQueEnamoran', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SweetSchmovies', u'query': u'%23SweetSchmovies', u'tweet_volume': None, u'name': u'#SweetSchmovies', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%ED%83%90%EB%9D%BC%EB%B0%B0_%EA%B1%B0%EC%A7%93%EB%A7%90_%EB%8C%80%ED%9A%8C', u'query': u'%23%ED%83%90%EB%9D%BC%EB%B0%B0_%EA%B1%B0%EC%A7%93%EB%A7%90_%EB%8C%80%ED%9A%8C', u'tweet_volume': None, u'name': u'#\ud0d0\ub77c\ubc30_\uac70\uc9d3\ub9d0_\ub300\ud68c', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D8%B5%D9%88%D8%B1%D9%87_%D8%B6%D9%8A%D8%B9%D8%AA_%D8%A7%D8%B3%D8%B1%D9%87', u'query': u'%23%D8%B5%D9%88%D8%B1%D9%87_%D8%B6%D9%8A%D8%B9%D8%AA_%D8%A7%D8%B3%D8%B1%D9%87', u'tweet_volume': None, u'name': u'#\u0635\u0648\u0631\u0647_\u0636\u064a\u0639\u062a_\u0627\u0633\u0631\u0647', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D9%85%D9%82%D8%A7%D8%B7%D8%B9%D9%87_%D8%B4%D8%B9%D9%8A%D8%A8_%D9%88%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D8%AC%D9%87', u'query': u'%23%D9%85%D9%82%D8%A7%D8%B7%D8%B9%D9%87_%D8%B4%D8%B9%D9%8A%D8%A8_%D9%88%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D8%AC%D9%87', u'tweet_volume': None, u'name': u'#\u0645\u0642\u0627\u0637\u0639\u0647_\u0634\u0639\u064a\u0628_\u0648\u0628\u0631\u0646\u0627\u0645\u062c\u0647', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D8%A7%D9%84%D9%82%D9%84%D8%A8_%D9%85%D9%86_%D8%A8%D8%B9%D8%AF%D9%83', u'query': u'%23%D8%A7%D9%84%D9%82%D9%84%D8%A8_%D9%85%D9%86_%D8%A8%D8%B9%D8%AF%D9%83', u'tweet_volume': None, u'name': u'#\u0627\u0644\u0642\u0644\u0628_\u0645\u0646_\u0628\u0639\u062f\u0643', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23%D0%A7%D1%83%D1%80%D0%BA%D0%B8%D0%BD', u'query': u'%23%D0%A7%D1%83%D1%80%D0%BA%D0%B8%D0%BD', u'tweet_volume': None, u'name': u'#\u0427\u0443\u0440\u043a\u0438\u043d', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23WawancaraCalonBesan', u'query': u'%23WawancaraCalonBesan', u'tweet_volume': None, u'name': u'#WawancaraCalonBesan', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23MeuSuperPoderEh', u'query': u'%23MeuSuperPoderEh', u'tweet_volume': 16993, u'name': u'#MeuSuperPoderEh', u'promoted_content': None}], u'as_of': u'2017-02-20T18:32:17Z', u'locations': [{u'woeid': 1, u'name': u'Worldwide'}]}]

[{u'created_at': u'2017-02-20T18:26:47Z', u'trends': [{u'url': u'http://twitter.com/search?q=%23PresidentsDay', u'query': u'%23PresidentsDay', u'tweet_volume': 254261, u'name': u'#PresidentsDay', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23NationalLoveYourPetDay', u'query': u'%23NationalLoveYourPetDay', u'tweet_volume': 26213, u'name': u'#NationalLoveYourPetDay', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23mondaymotivation', u'query': u'%23mondaymotivation', u'tweet_volume': 116212, u'name': u'#mondaymotivation', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23StrandedBae', u'query': u'%23StrandedBae', u'tweet_volume': 82936, u'name': u'#StrandedBae', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Vitaly+Churkin%22', u'query': u'%22Vitaly+Churkin%22', u'tweet_volume': 18852, u'name': u'Vitaly Churkin', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23TheyHiredMeAnyway', u'query': u'%23TheyHiredMeAnyway', u'tweet_volume': None, u'name': u'#TheyHiredMeAnyway', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Kurt+Cobain%22', u'query': u'%22Kurt+Cobain%22', u'tweet_volume': 85342, u'name': u'Kurt Cobain', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Donald+Trump+and+Russia%22', u'query': u'%22Donald+Trump+and+Russia%22', u'tweet_volume': None, u'name': u'Donald Trump and Russia', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22AP+Poll%22', u'query': u'%22AP+Poll%22', u'tweet_volume': None, u'name': u'AP Poll', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Player+of+the+Week%22', u'query': u'%22Player+of+the+Week%22', u'tweet_volume': None, u'name': u'Player of the Week', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Matt+Barnes%22', u'query': u'%22Matt+Barnes%22', u'tweet_volume': None, u'name': u'Matt Barnes', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22AP+Top+25%22', u'query': u'%22AP+Top+25%22', u'tweet_volume': None, u'name': u'AP Top 25', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=Nebula', u'query': u'Nebula', u'tweet_volume': None, u'name': u'Nebula', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Horizon+Zero+Dawn%22', u'query': u'%22Horizon+Zero+Dawn%22', u'tweet_volume': 30874, u'name': u'Horizon Zero Dawn', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22British+Parliament%22', u'query': u'%22British+Parliament%22', u'tweet_volume': None, u'name': u'British Parliament', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Snapchat+Spectacles%22', u'query': u'%22Snapchat+Spectacles%22', u'tweet_volume': None, u'name': u'Snapchat Spectacles', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Russian+Ambassador+to+the+UN%22', u'query': u'%22Russian+Ambassador+to+the+UN%22', u'tweet_volume': None, u'name': u'Russian Ambassador to the UN', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Daisy+Ridley%22', u'query': u'%22Daisy+Ridley%22', u'tweet_volume': None, u'name': u'Daisy Ridley', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=Brussels', u'query': u'Brussels', u'tweet_volume': 19441, u'name': u'Brussels', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Freshman+of+the+Week%22', u'query': u'%22Freshman+of+the+Week%22', u'tweet_volume': None, u'name': u'Freshman of the Week', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Diamond+Dallas+Page%22', u'query': u'%22Diamond+Dallas+Page%22', u'tweet_volume': None, u'name': u'Diamond Dallas Page', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=Malmo', u'query': u'Malmo', u'tweet_volume': 20874, u'name': u'Malmo', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=UBIQ', u'query': u'UBIQ', u'tweet_volume': None, u'name': u'UBIQ', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Julius+Thomas%22', u'query': u'%22Julius+Thomas%22', u'tweet_volume': None, u'name': u'Julius Thomas', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22John+Glenn%22', u'query': u'%22John+Glenn%22', u'tweet_volume': None, u'name': u'John Glenn', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Jack+Black%22', u'query': u'%22Jack+Black%22', u'tweet_volume': None, u'name': u'Jack Black', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22Brad+Bates%22', u'query': u'%22Brad+Bates%22', u'tweet_volume': None, u'name': u'Brad Bates', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22iOS+10.3%22', u'query': u'%22iOS+10.3%22', u'tweet_volume': None, u'name': u'iOS 10.3', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%22The+Predator%22', u'query': u'%22The+Predator%22', u'tweet_volume': None, u'name': u'The Predator', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23MusicMonday', u'query': u'%23MusicMonday', u'tweet_volume': None, u'name': u'#MusicMonday', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SweetSchmovies', u'query': u'%23SweetSchmovies', u'tweet_volume': None, u'name': u'#SweetSchmovies', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23WhatILearnedAtTheGym', u'query': u'%23WhatILearnedAtTheGym', u'tweet_volume': None, u'name': u'#WhatILearnedAtTheGym', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23CPAC', u'query': u'%23CPAC', u'tweet_volume': 15503, u'name': u'#CPAC', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23OscarsWeNeed', u'query': u'%23OscarsWeNeed', u'tweet_volume': None, u'name': u'#OscarsWeNeed', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23Outnumbered', u'query': u'%23Outnumbered', u'tweet_volume': None, u'name': u'#Outnumbered', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23HappyBirthdayRihanna', u'query': u'%23HappyBirthdayRihanna', u'tweet_volume': 91222, u'name': u'#HappyBirthdayRihanna', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23phxstartupweek', u'query': u'%23phxstartupweek', u'tweet_volume': None, u'name': u'#phxstartupweek', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23ObamaDay', u'query': u'%23ObamaDay', u'tweet_volume': None, u'name': u'#ObamaDay', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23MeatlessMonday', u'query': u'%23MeatlessMonday', u'tweet_volume': None, u'name': u'#MeatlessMonday', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23RootsPicnic', u'query': u'%23RootsPicnic', u'tweet_volume': None, u'name': u'#RootsPicnic', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23SB106', u'query': u'%23SB106', u'tweet_volume': None, u'name': u'#SB106', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23swhpn17', u'query': u'%23swhpn17', u'tweet_volume': None, u'name': u'#swhpn17', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23CousinsTrade', u'query': u'%23CousinsTrade', u'tweet_volume': None, u'name': u'#CousinsTrade', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23AnselAdams', u'query': u'%23AnselAdams', u'tweet_volume': None, u'name': u'#AnselAdams', u'promoted_content': None}, {u'url': u'http://twitter.com/search?q=%23MTGAKH', u'query': u'%23MTGAKH', u'tweet_volume': None, u'name': u'#MTGAKH', u'promoted_content': None}], u'as_of': u'2017-02-20T18:32:17Z', u'locations': [{u'woeid': 23424977, u'name': u'United States'}]}]

In [17]:
dir()


Out[17]:
['CONSUMER_KEY',
 'CONSUMER_SECRET',
 'Counter',
 'In',
 'OAUTH_TOKEN',
 'OAUTH_TOKEN_SECRET',
 'Out',
 'PrettyTable',
 'RUS_WOE_ID',
 'US_WOE_ID',
 'WORLD_WOE_ID',
 '_',
 '_3',
 '_7',
 '__',
 '___',
 '__builtin__',
 '__builtins__',
 '__doc__',
 '__name__',
 '__package__',
 '_dh',
 '_i',
 '_i1',
 '_i10',
 '_i11',
 '_i12',
 '_i13',
 '_i14',
 '_i15',
 '_i16',
 '_i17',
 '_i2',
 '_i3',
 '_i4',
 '_i5',
 '_i6',
 '_i7',
 '_i8',
 '_i9',
 '_ih',
 '_ii',
 '_iii',
 '_oh',
 '_sh',
 'auth',
 'average_words',
 'c',
 'common_trends',
 'count',
 'data',
 'e',
 'exit',
 'get_ipython',
 'hashtag',
 'hashtags',
 'item',
 'json',
 'kv',
 'label',
 'lexical_diversity',
 'max_num',
 'pt',
 'q',
 'quit',
 'retweets',
 'row',
 'rus_trends',
 'rus_trends_set',
 'screen_names',
 'search_results',
 'status',
 'status_texts',
 'statuses',
 't',
 'trend',
 'twitter',
 'twitter_api',
 'unquote',
 'us_trends',
 'us_trends_set',
 'user_mention',
 'w',
 'words',
 'world_trends',
 'world_trends_set']

Example 3. Displaying API responses as pretty-printed JSON


In [18]:
import json

print json.dumps(world_trends, indent=1)
print
print json.dumps(us_trends, indent=1)
print
print json.dumps(rus_trends, indent=1)


[
 {
  "created_at": "2017-02-20T18:26:47Z", 
  "trends": [
   {
    "url": "http://twitter.com/search?q=%23PresidentsDay", 
    "query": "%23PresidentsDay", 
    "tweet_volume": 254261, 
    "name": "#PresidentsDay", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D8%A7%D9%84%D8%AA%D8%B9%D8%A7%D9%88%D9%86_%D9%84%D9%88%D9%83%D9%88%D9%85%D9%88%D8%AA%D9%8A%D9%81", 
    "query": "%23%D8%A7%D9%84%D8%AA%D8%B9%D8%A7%D9%88%D9%86_%D9%84%D9%88%D9%83%D9%88%D9%85%D9%88%D8%AA%D9%8A%D9%81", 
    "tweet_volume": 71455, 
    "name": "#\u0627\u0644\u062a\u0639\u0627\u0648\u0646_\u0644\u0648\u0643\u0648\u0645\u0648\u062a\u064a\u0641", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23NationalLoveYourPetDay", 
    "query": "%23NationalLoveYourPetDay", 
    "tweet_volume": 26213, 
    "name": "#NationalLoveYourPetDay", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23WatchLoveOnVevo", 
    "query": "%23WatchLoveOnVevo", 
    "tweet_volume": 15678, 
    "name": "#WatchLoveOnVevo", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23DiaInternacionalDelGato", 
    "query": "%23DiaInternacionalDelGato", 
    "tweet_volume": 28526, 
    "name": "#DiaInternacionalDelGato", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Steve+Hewlett%22", 
    "query": "%22Steve+Hewlett%22", 
    "tweet_volume": null, 
    "name": "Steve Hewlett", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Vitaly+Churkin%22", 
    "query": "%22Vitaly+Churkin%22", 
    "tweet_volume": 18852, 
    "name": "Vitaly Churkin", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Kurt+Cobain%22", 
    "query": "%22Kurt+Cobain%22", 
    "tweet_volume": 85342, 
    "name": "Kurt Cobain", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Ally", 
    "query": "Ally", 
    "tweet_volume": 66058, 
    "name": "Ally", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Colmenares", 
    "query": "Colmenares", 
    "tweet_volume": 22768, 
    "name": "Colmenares", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=CEDAE", 
    "query": "CEDAE", 
    "tweet_volume": null, 
    "name": "CEDAE", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%ED%83%90%EB%9D%BC+%ED%8F%AC%EC%A7%80%EC%85%98%22", 
    "query": "%22%ED%83%90%EB%9D%BC+%ED%8F%AC%EC%A7%80%EC%85%98%22", 
    "tweet_volume": null, 
    "name": "\ud0d0\ub77c \ud3ec\uc9c0\uc158", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23SophiaAbrah%C3%A3oNoV%C3%ADdeoShow", 
    "query": "%23SophiaAbrah%C3%A3oNoV%C3%ADdeoShow", 
    "tweet_volume": 16066, 
    "name": "#SophiaAbrah\u00e3oNoV\u00eddeoShow", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D8%A7%D9%88%D9%82%D9%81%D9%88%D8%A7_%D8%AD%D9%85%D8%A7%D9%82%D8%A7%D8%AA_%D9%87%D9%8A%D9%8A%D9%87_%D8%A7%D9%84%D8%AA%D8%B1%D9%81%D9%8A%D9%87", 
    "query": "%23%D8%A7%D9%88%D9%82%D9%81%D9%88%D8%A7_%D8%AD%D9%85%D8%A7%D9%82%D8%A7%D8%AA_%D9%87%D9%8A%D9%8A%D9%87_%D8%A7%D9%84%D8%AA%D8%B1%D9%81%D9%8A%D9%87", 
    "tweet_volume": 19515, 
    "name": "#\u0627\u0648\u0642\u0641\u0648\u0627_\u062d\u0645\u0627\u0642\u0627\u062a_\u0647\u064a\u064a\u0647_\u0627\u0644\u062a\u0631\u0641\u064a\u0647", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D8%A7%D9%84%D8%A8%D9%8A%D8%AA_%D8%A7%D9%84%D9%87%D9%84%D8%A7%D9%84%D9%8A_%D9%8A%D8%BA%D9%84%D9%8A", 
    "query": "%23%D8%A7%D9%84%D8%A8%D9%8A%D8%AA_%D8%A7%D9%84%D9%87%D9%84%D8%A7%D9%84%D9%8A_%D9%8A%D8%BA%D9%84%D9%8A", 
    "tweet_volume": null, 
    "name": "#\u0627\u0644\u0628\u064a\u062a_\u0627\u0644\u0647\u0644\u0627\u0644\u064a_\u064a\u063a\u0644\u064a", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23FelizLunes", 
    "query": "%23FelizLunes", 
    "tweet_volume": 49998, 
    "name": "#FelizLunes", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23VidalEnDDM", 
    "query": "%23VidalEnDDM", 
    "tweet_volume": null, 
    "name": "#VidalEnDDM", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23StrandedBae", 
    "query": "%23StrandedBae", 
    "tweet_volume": 82936, 
    "name": "#StrandedBae", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23LQvIU", 
    "query": "%23LQvIU", 
    "tweet_volume": null, 
    "name": "#LQvIU", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D0%BF%D1%83%D1%81%D1%82%D1%8C%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D1%8F%D1%82", 
    "query": "%23%D0%BF%D1%83%D1%81%D1%82%D1%8C%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D1%8F%D1%82", 
    "tweet_volume": 11384, 
    "name": "#\u043f\u0443\u0441\u0442\u044c\u0433\u043e\u0432\u043e\u0440\u044f\u0442", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23DontSleepOnSeokJin", 
    "query": "%23DontSleepOnSeokJin", 
    "tweet_volume": 11858, 
    "name": "#DontSleepOnSeokJin", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23DitesLeABaba", 
    "query": "%23DitesLeABaba", 
    "tweet_volume": null, 
    "name": "#DitesLeABaba", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23FamilyDay", 
    "query": "%23FamilyDay", 
    "tweet_volume": 12008, 
    "name": "#FamilyDay", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23HappyWendyDay", 
    "query": "%23HappyWendyDay", 
    "tweet_volume": 97734, 
    "name": "#HappyWendyDay", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23tagdelyoutuberJs", 
    "query": "%23tagdelyoutuberJs", 
    "tweet_volume": null, 
    "name": "#tagdelyoutuberJs", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23BTSBrokeBangtansRecordParty", 
    "query": "%23BTSBrokeBangtansRecordParty", 
    "tweet_volume": 13178, 
    "name": "#BTSBrokeBangtansRecordParty", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23EVETvatanaSahip%C3%87%C4%B1k%C4%B1yoruz", 
    "query": "%23EVETvatanaSahip%C3%87%C4%B1k%C4%B1yoruz", 
    "tweet_volume": 19689, 
    "name": "#EVETvatanaSahip\u00c7\u0131k\u0131yoruz", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D9%85%D8%AD%D8%A7%D9%83%D9%85%D9%87_%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D8%B1%D8%AD%D9%85%D9%86_%D8%A7%D9%84%D9%85%D8%B7%D9%8A%D8%B1%D9%8A", 
    "query": "%23%D9%85%D8%AD%D8%A7%D9%83%D9%85%D9%87_%D8%B9%D8%A8%D8%AF%D8%A7%D9%84%D8%B1%D8%AD%D9%85%D9%86_%D8%A7%D9%84%D9%85%D8%B7%D9%8A%D8%B1%D9%8A", 
    "tweet_volume": 17122, 
    "name": "#\u0645\u062d\u0627\u0643\u0645\u0647_\u0639\u0628\u062f\u0627\u0644\u0631\u062d\u0645\u0646_\u0627\u0644\u0645\u0637\u064a\u0631\u064a", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%E3%81%93%E3%81%AE%E3%82%BF%E3%82%B0%E3%82%92%E8%A6%8B%E3%81%9F%E3%82%89%E6%80%96%E3%81%84%E3%82%82%E3%81%AE%E3%82%92%E3%81%B2%E3%81%A8%E3%81%A4%E3%81%82%E3%81%92%E3%82%8B", 
    "query": "%23%E3%81%93%E3%81%AE%E3%82%BF%E3%82%B0%E3%82%92%E8%A6%8B%E3%81%9F%E3%82%89%E6%80%96%E3%81%84%E3%82%82%E3%81%AE%E3%82%92%E3%81%B2%E3%81%A8%E3%81%A4%E3%81%82%E3%81%92%E3%82%8B", 
    "tweet_volume": 11125, 
    "name": "#\u3053\u306e\u30bf\u30b0\u3092\u898b\u305f\u3089\u6016\u3044\u3082\u306e\u3092\u3072\u3068\u3064\u3042\u3052\u308b", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D8%A7%D9%84%D8%A7%D9%87%D9%84%D9%8A_%D8%A7%D9%84%D8%A7%D8%B3%D8%AA%D9%82%D9%84%D8%A7%D9%84", 
    "query": "%23%D8%A7%D9%84%D8%A7%D9%87%D9%84%D9%8A_%D8%A7%D9%84%D8%A7%D8%B3%D8%AA%D9%82%D9%84%D8%A7%D9%84", 
    "tweet_volume": null, 
    "name": "#\u0627\u0644\u0627\u0647\u0644\u064a_\u0627\u0644\u0627\u0633\u062a\u0642\u0644\u0627\u0644", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23lagerhuis", 
    "query": "%23lagerhuis", 
    "tweet_volume": null, 
    "name": "#lagerhuis", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23SiMiVidaFueraUnaPelicula", 
    "query": "%23SiMiVidaFueraUnaPelicula", 
    "tweet_volume": null, 
    "name": "#SiMiVidaFueraUnaPelicula", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23TheyHiredMeAnyway", 
    "query": "%23TheyHiredMeAnyway", 
    "tweet_volume": null, 
    "name": "#TheyHiredMeAnyway", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23VATANi%C3%A7inHAYIR", 
    "query": "%23VATANi%C3%A7inHAYIR", 
    "tweet_volume": null, 
    "name": "#VATANi\u00e7inHAYIR", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%E3%81%84%E3%81%8B%E3%81%AE%E3%81%8A%E3%81%99%E3%81%97%E3%81%A7%E3%81%A9%E3%82%93%E3%81%AA%E4%BA%BA%E9%96%93%E3%81%8B%E3%83%90%E3%83%AC%E3%82%8B", 
    "query": "%23%E3%81%84%E3%81%8B%E3%81%AE%E3%81%8A%E3%81%99%E3%81%97%E3%81%A7%E3%81%A9%E3%82%93%E3%81%AA%E4%BA%BA%E9%96%93%E3%81%8B%E3%83%90%E3%83%AC%E3%82%8B", 
    "tweet_volume": null, 
    "name": "#\u3044\u304b\u306e\u304a\u3059\u3057\u3067\u3069\u3093\u306a\u4eba\u9593\u304b\u30d0\u30ec\u308b", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%2320FRevolucionZamorista", 
    "query": "%2320FRevolucionZamorista", 
    "tweet_volume": 10931, 
    "name": "#20FRevolucionZamorista", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23SegundaDetremuraSDV", 
    "query": "%23SegundaDetremuraSDV", 
    "tweet_volume": 14964, 
    "name": "#SegundaDetremuraSDV", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23kimkazanacak", 
    "query": "%23kimkazanacak", 
    "tweet_volume": 18866, 
    "name": "#kimkazanacak", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23SametBurakSar%C4%B1ya%C3%96zg%C3%BCrl%C3%BCk", 
    "query": "%23SametBurakSar%C4%B1ya%C3%96zg%C3%BCrl%C3%BCk", 
    "tweet_volume": null, 
    "name": "#SametBurakSar\u0131ya\u00d6zg\u00fcrl\u00fck", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23stoptrump", 
    "query": "%23stoptrump", 
    "tweet_volume": null, 
    "name": "#stoptrump", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23Eurogroup", 
    "query": "%23Eurogroup", 
    "tweet_volume": null, 
    "name": "#Eurogroup", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23CosasQueEnamoran", 
    "query": "%23CosasQueEnamoran", 
    "tweet_volume": null, 
    "name": "#CosasQueEnamoran", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23SweetSchmovies", 
    "query": "%23SweetSchmovies", 
    "tweet_volume": null, 
    "name": "#SweetSchmovies", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%ED%83%90%EB%9D%BC%EB%B0%B0_%EA%B1%B0%EC%A7%93%EB%A7%90_%EB%8C%80%ED%9A%8C", 
    "query": "%23%ED%83%90%EB%9D%BC%EB%B0%B0_%EA%B1%B0%EC%A7%93%EB%A7%90_%EB%8C%80%ED%9A%8C", 
    "tweet_volume": null, 
    "name": "#\ud0d0\ub77c\ubc30_\uac70\uc9d3\ub9d0_\ub300\ud68c", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D8%B5%D9%88%D8%B1%D9%87_%D8%B6%D9%8A%D8%B9%D8%AA_%D8%A7%D8%B3%D8%B1%D9%87", 
    "query": "%23%D8%B5%D9%88%D8%B1%D9%87_%D8%B6%D9%8A%D8%B9%D8%AA_%D8%A7%D8%B3%D8%B1%D9%87", 
    "tweet_volume": null, 
    "name": "#\u0635\u0648\u0631\u0647_\u0636\u064a\u0639\u062a_\u0627\u0633\u0631\u0647", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D9%85%D9%82%D8%A7%D8%B7%D8%B9%D9%87_%D8%B4%D8%B9%D9%8A%D8%A8_%D9%88%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D8%AC%D9%87", 
    "query": "%23%D9%85%D9%82%D8%A7%D8%B7%D8%B9%D9%87_%D8%B4%D8%B9%D9%8A%D8%A8_%D9%88%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D8%AC%D9%87", 
    "tweet_volume": null, 
    "name": "#\u0645\u0642\u0627\u0637\u0639\u0647_\u0634\u0639\u064a\u0628_\u0648\u0628\u0631\u0646\u0627\u0645\u062c\u0647", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D8%A7%D9%84%D9%82%D9%84%D8%A8_%D9%85%D9%86_%D8%A8%D8%B9%D8%AF%D9%83", 
    "query": "%23%D8%A7%D9%84%D9%82%D9%84%D8%A8_%D9%85%D9%86_%D8%A8%D8%B9%D8%AF%D9%83", 
    "tweet_volume": null, 
    "name": "#\u0627\u0644\u0642\u0644\u0628_\u0645\u0646_\u0628\u0639\u062f\u0643", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D0%A7%D1%83%D1%80%D0%BA%D0%B8%D0%BD", 
    "query": "%23%D0%A7%D1%83%D1%80%D0%BA%D0%B8%D0%BD", 
    "tweet_volume": null, 
    "name": "#\u0427\u0443\u0440\u043a\u0438\u043d", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23WawancaraCalonBesan", 
    "query": "%23WawancaraCalonBesan", 
    "tweet_volume": null, 
    "name": "#WawancaraCalonBesan", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23MeuSuperPoderEh", 
    "query": "%23MeuSuperPoderEh", 
    "tweet_volume": 16993, 
    "name": "#MeuSuperPoderEh", 
    "promoted_content": null
   }
  ], 
  "as_of": "2017-02-20T18:32:17Z", 
  "locations": [
   {
    "woeid": 1, 
    "name": "Worldwide"
   }
  ]
 }
]

[
 {
  "created_at": "2017-02-20T18:26:47Z", 
  "trends": [
   {
    "url": "http://twitter.com/search?q=%23PresidentsDay", 
    "query": "%23PresidentsDay", 
    "tweet_volume": 254261, 
    "name": "#PresidentsDay", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23NationalLoveYourPetDay", 
    "query": "%23NationalLoveYourPetDay", 
    "tweet_volume": 26213, 
    "name": "#NationalLoveYourPetDay", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23mondaymotivation", 
    "query": "%23mondaymotivation", 
    "tweet_volume": 116212, 
    "name": "#mondaymotivation", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23StrandedBae", 
    "query": "%23StrandedBae", 
    "tweet_volume": 82936, 
    "name": "#StrandedBae", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Vitaly+Churkin%22", 
    "query": "%22Vitaly+Churkin%22", 
    "tweet_volume": 18852, 
    "name": "Vitaly Churkin", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23TheyHiredMeAnyway", 
    "query": "%23TheyHiredMeAnyway", 
    "tweet_volume": null, 
    "name": "#TheyHiredMeAnyway", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Kurt+Cobain%22", 
    "query": "%22Kurt+Cobain%22", 
    "tweet_volume": 85342, 
    "name": "Kurt Cobain", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Donald+Trump+and+Russia%22", 
    "query": "%22Donald+Trump+and+Russia%22", 
    "tweet_volume": null, 
    "name": "Donald Trump and Russia", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22AP+Poll%22", 
    "query": "%22AP+Poll%22", 
    "tweet_volume": null, 
    "name": "AP Poll", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Player+of+the+Week%22", 
    "query": "%22Player+of+the+Week%22", 
    "tweet_volume": null, 
    "name": "Player of the Week", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Matt+Barnes%22", 
    "query": "%22Matt+Barnes%22", 
    "tweet_volume": null, 
    "name": "Matt Barnes", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22AP+Top+25%22", 
    "query": "%22AP+Top+25%22", 
    "tweet_volume": null, 
    "name": "AP Top 25", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Nebula", 
    "query": "Nebula", 
    "tweet_volume": null, 
    "name": "Nebula", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Horizon+Zero+Dawn%22", 
    "query": "%22Horizon+Zero+Dawn%22", 
    "tweet_volume": 30874, 
    "name": "Horizon Zero Dawn", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22British+Parliament%22", 
    "query": "%22British+Parliament%22", 
    "tweet_volume": null, 
    "name": "British Parliament", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Snapchat+Spectacles%22", 
    "query": "%22Snapchat+Spectacles%22", 
    "tweet_volume": null, 
    "name": "Snapchat Spectacles", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Russian+Ambassador+to+the+UN%22", 
    "query": "%22Russian+Ambassador+to+the+UN%22", 
    "tweet_volume": null, 
    "name": "Russian Ambassador to the UN", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Daisy+Ridley%22", 
    "query": "%22Daisy+Ridley%22", 
    "tweet_volume": null, 
    "name": "Daisy Ridley", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Brussels", 
    "query": "Brussels", 
    "tweet_volume": 19441, 
    "name": "Brussels", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Freshman+of+the+Week%22", 
    "query": "%22Freshman+of+the+Week%22", 
    "tweet_volume": null, 
    "name": "Freshman of the Week", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Diamond+Dallas+Page%22", 
    "query": "%22Diamond+Dallas+Page%22", 
    "tweet_volume": null, 
    "name": "Diamond Dallas Page", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Malmo", 
    "query": "Malmo", 
    "tweet_volume": 20874, 
    "name": "Malmo", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=UBIQ", 
    "query": "UBIQ", 
    "tweet_volume": null, 
    "name": "UBIQ", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Julius+Thomas%22", 
    "query": "%22Julius+Thomas%22", 
    "tweet_volume": null, 
    "name": "Julius Thomas", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22John+Glenn%22", 
    "query": "%22John+Glenn%22", 
    "tweet_volume": null, 
    "name": "John Glenn", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Jack+Black%22", 
    "query": "%22Jack+Black%22", 
    "tweet_volume": null, 
    "name": "Jack Black", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Brad+Bates%22", 
    "query": "%22Brad+Bates%22", 
    "tweet_volume": null, 
    "name": "Brad Bates", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22iOS+10.3%22", 
    "query": "%22iOS+10.3%22", 
    "tweet_volume": null, 
    "name": "iOS 10.3", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22The+Predator%22", 
    "query": "%22The+Predator%22", 
    "tweet_volume": null, 
    "name": "The Predator", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23MusicMonday", 
    "query": "%23MusicMonday", 
    "tweet_volume": null, 
    "name": "#MusicMonday", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23SweetSchmovies", 
    "query": "%23SweetSchmovies", 
    "tweet_volume": null, 
    "name": "#SweetSchmovies", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23WhatILearnedAtTheGym", 
    "query": "%23WhatILearnedAtTheGym", 
    "tweet_volume": null, 
    "name": "#WhatILearnedAtTheGym", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23CPAC", 
    "query": "%23CPAC", 
    "tweet_volume": 15503, 
    "name": "#CPAC", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23OscarsWeNeed", 
    "query": "%23OscarsWeNeed", 
    "tweet_volume": null, 
    "name": "#OscarsWeNeed", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23Outnumbered", 
    "query": "%23Outnumbered", 
    "tweet_volume": null, 
    "name": "#Outnumbered", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23HappyBirthdayRihanna", 
    "query": "%23HappyBirthdayRihanna", 
    "tweet_volume": 91222, 
    "name": "#HappyBirthdayRihanna", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23phxstartupweek", 
    "query": "%23phxstartupweek", 
    "tweet_volume": null, 
    "name": "#phxstartupweek", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23ObamaDay", 
    "query": "%23ObamaDay", 
    "tweet_volume": null, 
    "name": "#ObamaDay", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23MeatlessMonday", 
    "query": "%23MeatlessMonday", 
    "tweet_volume": null, 
    "name": "#MeatlessMonday", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23RootsPicnic", 
    "query": "%23RootsPicnic", 
    "tweet_volume": null, 
    "name": "#RootsPicnic", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23SB106", 
    "query": "%23SB106", 
    "tweet_volume": null, 
    "name": "#SB106", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23swhpn17", 
    "query": "%23swhpn17", 
    "tweet_volume": null, 
    "name": "#swhpn17", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23CousinsTrade", 
    "query": "%23CousinsTrade", 
    "tweet_volume": null, 
    "name": "#CousinsTrade", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23AnselAdams", 
    "query": "%23AnselAdams", 
    "tweet_volume": null, 
    "name": "#AnselAdams", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23MTGAKH", 
    "query": "%23MTGAKH", 
    "tweet_volume": null, 
    "name": "#MTGAKH", 
    "promoted_content": null
   }
  ], 
  "as_of": "2017-02-20T18:32:17Z", 
  "locations": [
   {
    "woeid": 23424977, 
    "name": "United States"
   }
  ]
 }
]

[
 {
  "created_at": "2017-02-20T18:26:49Z", 
  "trends": [
   {
    "url": "http://twitter.com/search?q=%23%D0%BF%D1%83%D1%81%D1%82%D1%8C%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D1%8F%D1%82", 
    "query": "%23%D0%BF%D1%83%D1%81%D1%82%D1%8C%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D1%8F%D1%82", 
    "tweet_volume": 11384, 
    "name": "#\u043f\u0443\u0441\u0442\u044c\u0433\u043e\u0432\u043e\u0440\u044f\u0442", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D1%82%D0%B0%D0%B2%D0%B0%D0%BD%D1%89%D0%B5%D1%80%D1%88%D1%8B%D0%B2%D1%84%D0%BE%D0%BB%D0%BB%D0%BE%D0%B2%D0%B8%D1%82%D0%B2%D1%81%D0%B5%D1%85", 
    "query": "%23%D1%82%D0%B0%D0%B2%D0%B0%D0%BD%D1%89%D0%B5%D1%80%D1%88%D1%8B%D0%B2%D1%84%D0%BE%D0%BB%D0%BB%D0%BE%D0%B2%D0%B8%D1%82%D0%B2%D1%81%D0%B5%D1%85", 
    "tweet_volume": null, 
    "name": "#\u0442\u0430\u0432\u0430\u043d\u0449\u0435\u0440\u0448\u044b\u0432\u0444\u043e\u043b\u043b\u043e\u0432\u0438\u0442\u0432\u0441\u0435\u0445", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%9E%D0%9E%D0%9D+%D0%92%D0%B8%D1%82%D0%B0%D0%BB%D0%B8%D0%B9+%D0%A7%D1%83%D1%80%D0%BA%D0%B8%D0%BD%22", 
    "query": "%22%D0%9E%D0%9E%D0%9D+%D0%92%D0%B8%D1%82%D0%B0%D0%BB%D0%B8%D0%B9+%D0%A7%D1%83%D1%80%D0%BA%D0%B8%D0%BD%22", 
    "tweet_volume": null, 
    "name": "\u041e\u041e\u041d \u0412\u0438\u0442\u0430\u043b\u0438\u0439 \u0427\u0443\u0440\u043a\u0438\u043d", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%A8%D1%83%D1%80%D1%8B%D0%B3%D0%B8%D0%BD%D0%BE%D0%B9", 
    "query": "%D0%A8%D1%83%D1%80%D1%8B%D0%B3%D0%B8%D0%BD%D0%BE%D0%B9", 
    "tweet_volume": 10524, 
    "name": "\u0428\u0443\u0440\u044b\u0433\u0438\u043d\u043e\u0439", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22Vitaly+Churkin%22", 
    "query": "%22Vitaly+Churkin%22", 
    "tweet_volume": 18852, 
    "name": "Vitaly Churkin", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23RussiaLovesEd", 
    "query": "%23RussiaLovesEd", 
    "tweet_volume": null, 
    "name": "#RussiaLovesEd", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%9C%D0%B0%D1%80%D0%B8%D0%BD+%D0%9B%D0%B5+%D0%9F%D0%B5%D0%BD%22", 
    "query": "%22%D0%9C%D0%B0%D1%80%D0%B8%D0%BD+%D0%9B%D0%B5+%D0%9F%D0%B5%D0%BD%22", 
    "tweet_volume": null, 
    "name": "\u041c\u0430\u0440\u0438\u043d \u041b\u0435 \u041f\u0435\u043d", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%A2-90%D0%9C%D0%A1", 
    "query": "%D0%A2-90%D0%9C%D0%A1", 
    "tweet_volume": null, 
    "name": "\u0422-90\u041c\u0421", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%9B%D0%B0%D0%BD%D1%8B", 
    "query": "%D0%9B%D0%B0%D0%BD%D1%8B", 
    "tweet_volume": null, 
    "name": "\u041b\u0430\u043d\u044b", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%92+%D0%A1%D0%B8%D1%80%D0%B8%D0%B8%22", 
    "query": "%22%D0%92+%D0%A1%D0%B8%D1%80%D0%B8%D0%B8%22", 
    "tweet_volume": null, 
    "name": "\u0412 \u0421\u0438\u0440\u0438\u0438", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22iPhone+7%22", 
    "query": "%22iPhone+7%22", 
    "tweet_volume": 33998, 
    "name": "iPhone 7", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23VideoLove", 
    "query": "%23VideoLove", 
    "tweet_volume": 1208754, 
    "name": "#VideoLove", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D0%B2%D0%BA%D0%B6%D0%B8%D0%B2%D0%B8", 
    "query": "%23%D0%B2%D0%BA%D0%B6%D0%B8%D0%B2%D0%B8", 
    "tweet_volume": null, 
    "name": "#\u0432\u043a\u0436\u0438\u0432\u0438", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%94%D0%9D%D0%A0+%D0%B8+%D0%9B%D0%9D%D0%A0%22", 
    "query": "%22%D0%94%D0%9D%D0%A0+%D0%B8+%D0%9B%D0%9D%D0%A0%22", 
    "tweet_volume": null, 
    "name": "\u0414\u041d\u0420 \u0438 \u041b\u041d\u0420", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%A7%D0%B5%D1%80%D0%BD%D0%BE%D0%B3%D0%BE%D1%80%D0%B8%D0%B8", 
    "query": "%D0%A7%D0%B5%D1%80%D0%BD%D0%BE%D0%B3%D0%BE%D1%80%D0%B8%D0%B8", 
    "tweet_volume": null, 
    "name": "\u0427\u0435\u0440\u043d\u043e\u0433\u043e\u0440\u0438\u0438", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%A1%D1%82%D0%B0%D0%BB%D0%B8%D0%BD%D0%B3%D1%80%D0%B0%D0%B4%D1%81%D0%BA%D0%BE%D0%B9", 
    "query": "%D0%A1%D1%82%D0%B0%D0%BB%D0%B8%D0%BD%D0%B3%D1%80%D0%B0%D0%B4%D1%81%D0%BA%D0%BE%D0%B9", 
    "tweet_volume": null, 
    "name": "\u0421\u0442\u0430\u043b\u0438\u043d\u0433\u0440\u0430\u0434\u0441\u043a\u043e\u0439", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%9C%D0%B0%D0%B9%D0%B4%D0%B0%D0%BD%D0%B5", 
    "query": "%D0%9C%D0%B0%D0%B9%D0%B4%D0%B0%D0%BD%D0%B5", 
    "tweet_volume": null, 
    "name": "\u041c\u0430\u0439\u0434\u0430\u043d\u0435", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%9E%D0%BB%D1%8C%D0%B3%D0%B0+%D0%92%D0%B0%D1%81%D0%B8%D0%BB%D1%8C%D0%B5%D0%B2%D0%B0%22", 
    "query": "%22%D0%9E%D0%BB%D1%8C%D0%B3%D0%B0+%D0%92%D0%B0%D1%81%D0%B8%D0%BB%D1%8C%D0%B5%D0%B2%D0%B0%22", 
    "tweet_volume": null, 
    "name": "\u041e\u043b\u044c\u0433\u0430 \u0412\u0430\u0441\u0438\u043b\u044c\u0435\u0432\u0430", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%9C%D1%8B%D1%82%D0%B8%D1%89%D0%B0%D1%85", 
    "query": "%D0%9C%D1%8B%D1%82%D0%B8%D1%89%D0%B0%D1%85", 
    "tweet_volume": null, 
    "name": "\u041c\u044b\u0442\u0438\u0449\u0430\u0445", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%9D%D0%B0+%D0%9A%D0%B0%D0%BC%D1%87%D0%B0%D1%82%D0%BA%D0%B5%22", 
    "query": "%22%D0%9D%D0%B0+%D0%9A%D0%B0%D0%BC%D1%87%D0%B0%D1%82%D0%BA%D0%B5%22", 
    "tweet_volume": null, 
    "name": "\u041d\u0430 \u041a\u0430\u043c\u0447\u0430\u0442\u043a\u0435", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%AD%D0%BA%D0%B2%D0%B0%D0%B4%D0%BE%D1%80%D0%B5", 
    "query": "%D0%AD%D0%BA%D0%B2%D0%B0%D0%B4%D0%BE%D1%80%D0%B5", 
    "tweet_volume": null, 
    "name": "\u042d\u043a\u0432\u0430\u0434\u043e\u0440\u0435", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%93%D0%B8%D0%B1%D1%80%D0%B0%D0%BB%D1%82%D0%B0%D1%80%D0%B5", 
    "query": "%D0%93%D0%B8%D0%B1%D1%80%D0%B0%D0%BB%D1%82%D0%B0%D1%80%D0%B5", 
    "tweet_volume": null, 
    "name": "\u0413\u0438\u0431\u0440\u0430\u043b\u0442\u0430\u0440\u0435", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%92+%D0%A3%D0%BB%D1%8C%D1%8F%D0%BD%D0%BE%D0%B2%D1%81%D0%BA%D0%B5%22", 
    "query": "%22%D0%92+%D0%A3%D0%BB%D1%8C%D1%8F%D0%BD%D0%BE%D0%B2%D1%81%D0%BA%D0%B5%22", 
    "tweet_volume": null, 
    "name": "\u0412 \u0423\u043b\u044c\u044f\u043d\u043e\u0432\u0441\u043a\u0435", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%A1%D0%98%D0%97%D0%9E", 
    "query": "%D0%A1%D0%98%D0%97%D0%9E", 
    "tweet_volume": null, 
    "name": "\u0421\u0418\u0417\u041e", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%90%D0%BD%D0%B6%D0%B8%22", 
    "query": "%22%D0%90%D0%BD%D0%B6%D0%B8%22", 
    "tweet_volume": null, 
    "name": "\"\u0410\u043d\u0436\u0438\"", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%9A%D1%83%D1%80%D1%82+%D0%9A%D0%BE%D0%B1%D0%B5%D0%B9%D0%BD%22", 
    "query": "%22%D0%9A%D1%83%D1%80%D1%82+%D0%9A%D0%BE%D0%B1%D0%B5%D0%B9%D0%BD%22", 
    "tweet_volume": null, 
    "name": "\u041a\u0443\u0440\u0442 \u041a\u043e\u0431\u0435\u0439\u043d", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F+%D0%B8+%D0%9A%D0%B0%D1%82%D0%B0%D1%80%22", 
    "query": "%22%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D1%8F+%D0%B8+%D0%9A%D0%B0%D1%82%D0%B0%D1%80%22", 
    "tweet_volume": null, 
    "name": "\u0420\u043e\u0441\u0441\u0438\u044f \u0438 \u041a\u0430\u0442\u0430\u0440", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=Dragon", 
    "query": "Dragon", 
    "tweet_volume": 107073, 
    "name": "Dragon", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%9A%D0%B8%D0%B5%D0%B2%D0%B0", 
    "query": "%D0%9A%D0%B8%D0%B5%D0%B2%D0%B0", 
    "tweet_volume": null, 
    "name": "\u041a\u0438\u0435\u0432\u0430", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%22%D0%93%D0%BB%D0%B0%D0%B2%D0%B0+%D0%9F%D0%B5%D0%BD%D1%82%D0%B0%D0%B3%D0%BE%D0%BD%D0%B0%22", 
    "query": "%22%D0%93%D0%BB%D0%B0%D0%B2%D0%B0+%D0%9F%D0%B5%D0%BD%D1%82%D0%B0%D0%B3%D0%BE%D0%BD%D0%B0%22", 
    "tweet_volume": null, 
    "name": "\u0413\u043b\u0430\u0432\u0430 \u041f\u0435\u043d\u0442\u0430\u0433\u043e\u043d\u0430", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%D0%9F%D0%BE%D0%BB%D1%8C%D1%88%D0%B8", 
    "query": "%D0%9F%D0%BE%D0%BB%D1%8C%D1%88%D0%B8", 
    "tweet_volume": null, 
    "name": "\u041f\u043e\u043b\u044c\u0448\u0438", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D0%9C%D0%B0%D1%81%D0%BB%D0%B5%D0%BD%D0%B8%D1%86%D0%B0", 
    "query": "%23%D0%9C%D0%B0%D1%81%D0%BB%D0%B5%D0%BD%D0%B8%D1%86%D0%B0", 
    "tweet_volume": null, 
    "name": "#\u041c\u0430\u0441\u043b\u0435\u043d\u0438\u0446\u0430", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23mtv%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D1%8B%D0%B9%D1%87%D0%B0%D1%81", 
    "query": "%23mtv%D0%BA%D0%BB%D0%B0%D1%81%D1%81%D0%BD%D1%8B%D0%B9%D1%87%D0%B0%D1%81", 
    "tweet_volume": null, 
    "name": "#mtv\u043a\u043b\u0430\u0441\u0441\u043d\u044b\u0439\u0447\u0430\u0441", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D0%91%D1%83%D1%80%D1%8F%D1%82%D0%B8%D1%8F", 
    "query": "%23%D0%91%D1%83%D1%80%D1%8F%D1%82%D0%B8%D1%8F", 
    "tweet_volume": null, 
    "name": "#\u0411\u0443\u0440\u044f\u0442\u0438\u044f", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D0%9A%D1%83%D1%80%D1%81%D0%BA", 
    "query": "%23%D0%9A%D1%83%D1%80%D1%81%D0%BA", 
    "tweet_volume": null, 
    "name": "#\u041a\u0443\u0440\u0441\u043a", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23%D0%A0%D0%A4%D0%9F%D0%9B", 
    "query": "%23%D0%A0%D0%A4%D0%9F%D0%9B", 
    "tweet_volume": null, 
    "name": "#\u0420\u0424\u041f\u041b", 
    "promoted_content": null
   }, 
   {
    "url": "http://twitter.com/search?q=%23KimJongNam", 
    "query": "%23KimJongNam", 
    "tweet_volume": null, 
    "name": "#KimJongNam", 
    "promoted_content": null
   }
  ], 
  "as_of": "2017-02-20T18:32:18Z", 
  "locations": [
   {
    "woeid": 2122265, 
    "name": "Moscow"
   }
  ]
 }
]

In [19]:
world_trends_set = set([trend['name'] 
                        for trend in world_trends[0]['trends']])

us_trends_set = set([trend['name'] 
                     for trend in us_trends[0]['trends']])

rus_trends_set = set([trend['name'] 
                     for trend in rus_trends[0]['trends']]) 

common_trends = world_trends_set.intersection(us_trends_set, rus_trends_set)
print common_trends
common_trends = world_trends_set.intersection(us_trends_set)
print common_trends
common_trends = world_trends_set.intersection(rus_trends_set)
print common_trends


set([u'Vitaly Churkin'])
set([u'#PresidentsDay', u'#NationalLoveYourPetDay', u'Kurt Cobain', u'Vitaly Churkin', u'#StrandedBae', u'#TheyHiredMeAnyway', u'#SweetSchmovies'])
set([u'#\u043f\u0443\u0441\u0442\u044c\u0433\u043e\u0432\u043e\u0440\u044f\u0442', u'Vitaly Churkin'])

Example 5. Collecting search results


In [20]:
# Import unquote to prevent url encoding errors in next_results
from urllib import unquote

# XXX: Set this variable to a trending topic, 
# or anything else for that matter. The example query below
# was a trending topic when this content was being developed
# and is used throughout the remainder of this chapter.

q = '#success' 

count = 100

# See https://dev.twitter.com/docs/api/1.1/get/search/tweets

search_results = twitter_api.search.tweets(q=q, count=count)

statuses = search_results['statuses']


# Iterate through 5 more batches of results by following the cursor

for _ in range(5):
    print "Length of statuses", len(statuses)
    try:
        next_results = search_results['search_metadata']['next_results']
    except KeyError, e: # No more results when next_results doesn't exist
        break
        
    # Create a dictionary from next_results, which has the following form:
    # ?max_id=313519052523986943&q=NCAA&include_entities=1
    kwargs = dict([ kv.split('=') for kv in unquote(next_results[1:]).split("&") ])
    
    search_results = twitter_api.search.tweets(**kwargs)
    statuses += search_results['statuses']

# Show one sample search result by slicing the list...
print json.dumps(statuses[0], indent=1)


Length of statuses 100
Length of statuses 200
Length of statuses 300
Length of statuses 395
{
 "contributors": null, 
 "truncated": false, 
 "text": "RT @theRealKiyosaki: #richdad #knowledge #success #entrepreneur #financialeducation https://t.co/fOtF50rl7M", 
 "is_quote_status": false, 
 "in_reply_to_status_id": null, 
 "id": 833746049860763649, 
 "favorite_count": 0, 
 "entities": {
  "symbols": [], 
  "user_mentions": [
   {
    "id": 29856819, 
    "indices": [
     3, 
     19
    ], 
    "id_str": "29856819", 
    "screen_name": "theRealKiyosaki", 
    "name": "Robert T. Kiyosaki"
   }
  ], 
  "hashtags": [
   {
    "indices": [
     21, 
     29
    ], 
    "text": "richdad"
   }, 
   {
    "indices": [
     30, 
     40
    ], 
    "text": "knowledge"
   }, 
   {
    "indices": [
     41, 
     49
    ], 
    "text": "success"
   }, 
   {
    "indices": [
     50, 
     63
    ], 
    "text": "entrepreneur"
   }, 
   {
    "indices": [
     64, 
     83
    ], 
    "text": "financialeducation"
   }
  ], 
  "urls": [], 
  "media": [
   {
    "source_user_id": 29856819, 
    "source_status_id_str": "833662491469115393", 
    "expanded_url": "https://twitter.com/theRealKiyosaki/status/833662491469115393/photo/1", 
    "display_url": "pic.twitter.com/fOtF50rl7M", 
    "url": "https://t.co/fOtF50rl7M", 
    "media_url_https": "https://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg", 
    "source_user_id_str": "29856819", 
    "source_status_id": 833662491469115393, 
    "id_str": "832706645893353472", 
    "sizes": {
     "small": {
      "h": 432, 
      "resize": "fit", 
      "w": 680
     }, 
     "large": {
      "h": 800, 
      "resize": "fit", 
      "w": 1260
     }, 
     "medium": {
      "h": 762, 
      "resize": "fit", 
      "w": 1200
     }, 
     "thumb": {
      "h": 150, 
      "resize": "crop", 
      "w": 150
     }
    }, 
    "indices": [
     84, 
     107
    ], 
    "type": "photo", 
    "id": 832706645893353472, 
    "media_url": "http://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg"
   }
  ]
 }, 
 "retweeted": false, 
 "coordinates": null, 
 "source": "<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>", 
 "in_reply_to_screen_name": null, 
 "in_reply_to_user_id": null, 
 "retweet_count": 178, 
 "id_str": "833746049860763649", 
 "favorited": false, 
 "retweeted_status": {
  "contributors": null, 
  "truncated": false, 
  "text": "#richdad #knowledge #success #entrepreneur #financialeducation https://t.co/fOtF50rl7M", 
  "is_quote_status": false, 
  "in_reply_to_status_id": null, 
  "id": 833662491469115393, 
  "favorite_count": 285, 
  "entities": {
   "symbols": [], 
   "user_mentions": [], 
   "hashtags": [
    {
     "indices": [
      0, 
      8
     ], 
     "text": "richdad"
    }, 
    {
     "indices": [
      9, 
      19
     ], 
     "text": "knowledge"
    }, 
    {
     "indices": [
      20, 
      28
     ], 
     "text": "success"
    }, 
    {
     "indices": [
      29, 
      42
     ], 
     "text": "entrepreneur"
    }, 
    {
     "indices": [
      43, 
      62
     ], 
     "text": "financialeducation"
    }
   ], 
   "urls": [], 
   "media": [
    {
     "expanded_url": "https://twitter.com/theRealKiyosaki/status/833662491469115393/photo/1", 
     "display_url": "pic.twitter.com/fOtF50rl7M", 
     "url": "https://t.co/fOtF50rl7M", 
     "media_url_https": "https://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg", 
     "id_str": "832706645893353472", 
     "sizes": {
      "small": {
       "h": 432, 
       "resize": "fit", 
       "w": 680
      }, 
      "large": {
       "h": 800, 
       "resize": "fit", 
       "w": 1260
      }, 
      "medium": {
       "h": 762, 
       "resize": "fit", 
       "w": 1200
      }, 
      "thumb": {
       "h": 150, 
       "resize": "crop", 
       "w": 150
      }
     }, 
     "indices": [
      63, 
      86
     ], 
     "type": "photo", 
     "id": 832706645893353472, 
     "media_url": "http://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg"
    }
   ]
  }, 
  "retweeted": false, 
  "coordinates": null, 
  "source": "<a href=\"https://about.twitter.com/products/tweetdeck\" rel=\"nofollow\">TweetDeck</a>", 
  "in_reply_to_screen_name": null, 
  "in_reply_to_user_id": null, 
  "retweet_count": 178, 
  "id_str": "833662491469115393", 
  "favorited": false, 
  "user": {
   "follow_request_sent": false, 
   "has_extended_profile": true, 
   "profile_use_background_image": true, 
   "default_profile_image": false, 
   "id": 29856819, 
   "profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/378800000042701722/dc3748b6088c3a1d25f028e6200e1e5f.jpeg", 
   "verified": true, 
   "translator_type": "none", 
   "profile_text_color": "8A8A8A", 
   "profile_image_url_https": "https://pbs.twimg.com/profile_images/472421066007015424/MHUJj15g_normal.jpeg", 
   "profile_sidebar_fill_color": "171717", 
   "entities": {
    "url": {
     "urls": [
      {
       "url": "http://t.co/jbQZgSKDQg", 
       "indices": [
        0, 
        22
       ], 
       "expanded_url": "http://richdad.com", 
       "display_url": "richdad.com"
      }
     ]
    }, 
    "description": {
     "urls": []
    }
   }, 
   "followers_count": 1039190, 
   "profile_sidebar_border_color": "FFFFFF", 
   "id_str": "29856819", 
   "profile_background_color": "C4C7C8", 
   "listed_count": 10663, 
   "is_translation_enabled": false, 
   "utc_offset": -25200, 
   "statuses_count": 5089, 
   "description": "Investor | Entrepreneur | Financial Education Advocate | Author", 
   "friends_count": 64, 
   "location": "Scottsdale, Arizona, USA", 
   "profile_link_color": "612166", 
   "profile_image_url": "http://pbs.twimg.com/profile_images/472421066007015424/MHUJj15g_normal.jpeg", 
   "following": false, 
   "geo_enabled": true, 
   "profile_banner_url": "https://pbs.twimg.com/profile_banners/29856819/1401481831", 
   "profile_background_image_url": "http://pbs.twimg.com/profile_background_images/378800000042701722/dc3748b6088c3a1d25f028e6200e1e5f.jpeg", 
   "screen_name": "theRealKiyosaki", 
   "lang": "en", 
   "profile_background_tile": false, 
   "favourites_count": 184, 
   "name": "Robert T. Kiyosaki", 
   "notifications": false, 
   "url": "http://t.co/jbQZgSKDQg", 
   "created_at": "Wed Apr 08 23:40:16 +0000 2009", 
   "contributors_enabled": false, 
   "time_zone": "Arizona", 
   "protected": false, 
   "default_profile": false, 
   "is_translator": false
  }, 
  "geo": null, 
  "in_reply_to_user_id_str": null, 
  "possibly_sensitive": false, 
  "lang": "und", 
  "created_at": "Mon Feb 20 13:00:01 +0000 2017", 
  "in_reply_to_status_id_str": null, 
  "place": null, 
  "extended_entities": {
   "media": [
    {
     "expanded_url": "https://twitter.com/theRealKiyosaki/status/833662491469115393/photo/1", 
     "display_url": "pic.twitter.com/fOtF50rl7M", 
     "url": "https://t.co/fOtF50rl7M", 
     "media_url_https": "https://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg", 
     "id_str": "832706645893353472", 
     "sizes": {
      "small": {
       "h": 432, 
       "resize": "fit", 
       "w": 680
      }, 
      "large": {
       "h": 800, 
       "resize": "fit", 
       "w": 1260
      }, 
      "medium": {
       "h": 762, 
       "resize": "fit", 
       "w": 1200
      }, 
      "thumb": {
       "h": 150, 
       "resize": "crop", 
       "w": 150
      }
     }, 
     "indices": [
      63, 
      86
     ], 
     "type": "photo", 
     "id": 832706645893353472, 
     "media_url": "http://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg"
    }
   ]
  }, 
  "metadata": {
   "iso_language_code": "und", 
   "result_type": "recent"
  }
 }, 
 "user": {
  "follow_request_sent": false, 
  "has_extended_profile": false, 
  "profile_use_background_image": true, 
  "default_profile_image": false, 
  "id": 100407449, 
  "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png", 
  "verified": false, 
  "translator_type": "none", 
  "profile_text_color": "333333", 
  "profile_image_url_https": "https://pbs.twimg.com/profile_images/761691803137343488/C9hArLNo_normal.jpg", 
  "profile_sidebar_fill_color": "DDEEF6", 
  "entities": {
   "description": {
    "urls": []
   }
  }, 
  "followers_count": 52, 
  "profile_sidebar_border_color": "C0DEED", 
  "id_str": "100407449", 
  "profile_background_color": "C0DEED", 
  "listed_count": 3, 
  "is_translation_enabled": false, 
  "utc_offset": -21600, 
  "statuses_count": 310, 
  "description": "", 
  "friends_count": 54, 
  "location": "", 
  "profile_link_color": "1DA1F2", 
  "profile_image_url": "http://pbs.twimg.com/profile_images/761691803137343488/C9hArLNo_normal.jpg", 
  "following": false, 
  "geo_enabled": true, 
  "profile_banner_url": "https://pbs.twimg.com/profile_banners/100407449/1451451500", 
  "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png", 
  "screen_name": "kanalerik", 
  "lang": "en", 
  "profile_background_tile": false, 
  "favourites_count": 17, 
  "name": "erik gonzalez", 
  "notifications": false, 
  "url": null, 
  "created_at": "Wed Dec 30 04:49:38 +0000 2009", 
  "contributors_enabled": false, 
  "time_zone": "Mexico City", 
  "protected": false, 
  "default_profile": true, 
  "is_translator": false
 }, 
 "geo": null, 
 "in_reply_to_user_id_str": null, 
 "possibly_sensitive": false, 
 "lang": "und", 
 "created_at": "Mon Feb 20 18:32:03 +0000 2017", 
 "in_reply_to_status_id_str": null, 
 "place": null, 
 "extended_entities": {
  "media": [
   {
    "source_user_id": 29856819, 
    "source_status_id_str": "833662491469115393", 
    "expanded_url": "https://twitter.com/theRealKiyosaki/status/833662491469115393/photo/1", 
    "display_url": "pic.twitter.com/fOtF50rl7M", 
    "url": "https://t.co/fOtF50rl7M", 
    "media_url_https": "https://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg", 
    "source_user_id_str": "29856819", 
    "source_status_id": 833662491469115393, 
    "id_str": "832706645893353472", 
    "sizes": {
     "small": {
      "h": 432, 
      "resize": "fit", 
      "w": 680
     }, 
     "large": {
      "h": 800, 
      "resize": "fit", 
      "w": 1260
     }, 
     "medium": {
      "h": 762, 
      "resize": "fit", 
      "w": 1200
     }, 
     "thumb": {
      "h": 150, 
      "resize": "crop", 
      "w": 150
     }
    }, 
    "indices": [
     84, 
     107
    ], 
    "type": "photo", 
    "id": 832706645893353472, 
    "media_url": "http://pbs.twimg.com/media/C45eSFaUkAAm7tN.jpg"
   }
  ]
 }, 
 "metadata": {
  "iso_language_code": "und", 
  "result_type": "recent"
 }
}

In [21]:
type(statuses)


Out[21]:
list

In [22]:
# get the most retweeted tweet
max_num = 0
for status in statuses:
    if status['retweet_count'] > max_num:
        max_num = status['retweet_count']

print max_num


249

Example 6. Extracting text, screen names, and hashtags from tweets


In [23]:
status_texts = [ status['text']   for status in statuses ]

screen_names = [ user_mention['screen_name'] 
                 for status in statuses
                     for user_mention in status['entities']['user_mentions'] ]

hashtags = [ hashtag['text'] 
             for status in statuses
                 for hashtag in status['entities']['hashtags'] ]

# Compute a collection of all words from all tweets
words = [ w 
          for t in status_texts 
              for w in t.split() ]

# Explore the first 5 items for each...

print json.dumps(status_texts[0:5], indent=1)
print json.dumps(screen_names[0:5], indent=1) 
print json.dumps(hashtags[0:5], indent=1)
print json.dumps(words[0:5], indent=1)


[
 "RT @theRealKiyosaki: #richdad #knowledge #success #entrepreneur #financialeducation https://t.co/fOtF50rl7M", 
 "#Creative and #innovative ways to reward and measure #success - Frank Contrepois https://t.co/nBljmn7HNu #savetime https://t.co/0JW7lzfpja", 
 "Until you change your thinking you will always recycle your experiences. #mondaymotivation #motivation #success\u2026 https://t.co/DlWwvJwerM", 
 "RT @VeganYogaDude: This! Do this! And have a great week\n#mondaymotivation #Startup #Success #MakeYourOwnLane #defstar5 #mpgvip #inspiration\u2026", 
 "RT @LoriMoreno: Your Choices Now = Your Future\nChoose Wisely &amp; Intentionally \n@LoriMoreno #success #quote\nhttps://t.co/Sc0aTzGwox https://t\u2026"
]
[
 "theRealKiyosaki", 
 "VeganYogaDude", 
 "LoriMoreno", 
 "LoriMoreno", 
 "JonAlsup"
]
[
 "richdad", 
 "knowledge", 
 "success", 
 "entrepreneur", 
 "financialeducation"
]
[
 "RT", 
 "@theRealKiyosaki:", 
 "#richdad", 
 "#knowledge", 
 "#success"
]

Example 7. Creating a basic frequency distribution from the words in tweets


In [24]:
from collections import Counter

for item in [words, screen_names, hashtags]:
    c = Counter(item)
    print c.most_common()[:10] # top 10
    print


[(u'#success', 246), (u'RT', 142), (u'to', 123), (u'#Success', 109), (u'you', 84), (u'the', 83), (u'is', 68), (u'a', 57), (u'#motivation', 55), (u'#quote', 53)]

[(u'marshawright', 14), (u'LoriMoreno', 14), (u'Deep_nepalinfo', 13), (u'VeganYogaDude', 9), (u'ChrisPercival_', 8), (u'TheZigZiglar', 5), (u'_GarethG', 4), (u'NorthStarMarket', 4), (u'GeorgeGEdwards', 4), (u'SavvyCleaner', 3)]

[(u'success', 260), (u'Success', 114), (u'motivation', 63), (u'quote', 53), (u'entrepreneur', 32), (u'Entrepreneur', 30), (u'defstar5', 29), (u'Startup', 28), (u'MakeYourOwnLane', 25), (u'mpgvip', 25)]


In [25]:
print json.dumps(screen_names, indent=1)


[
 "theRealKiyosaki", 
 "VeganYogaDude", 
 "LoriMoreno", 
 "LoriMoreno", 
 "JonAlsup", 
 "luannnovotny", 
 "VeganYogaDude", 
 "TheZigZiglar", 
 "ActionComplete", 
 "jeansergegagnon", 
 "VeroDePrycker", 
 "DrPriceMitchell", 
 "Jonwestenberg", 
 "Entrepreneur", 
 "VeganYogaDude", 
 "First_Global", 
 "marshawright", 
 "gede_prama", 
 "JaniceKobelsky", 
 "marshawright", 
 "wmharris101", 
 "RyanGlass4reals", 
 "marshawright", 
 "ebookfriendly", 
 "Forbes", 
 "RyanGlass4reals", 
 "marshawright", 
 "CoachBrettBlair", 
 "tinybuddha", 
 "GeorgeGEdwards", 
 "TheFrugalennial", 
 "ericries", 
 "ActionComplete", 
 "GeorgeGEdwards", 
 "drudgeheadlines", 
 "LoriMoreno", 
 "LoriMoreno", 
 "VeganYogaDude", 
 "robertoglezcano", 
 "ChrisPercival_", 
 "ChrisPercival_", 
 "GeorgeGEdwards", 
 "LightStalking", 
 "GeorgeGEdwards", 
 "ChrisPercival_", 
 "TheZigZiglar", 
 "marshawright", 
 "ChrisPercival_", 
 "A631St4n13y", 
 "marshawright", 
 "DonaDeane", 
 "marshawright", 
 "sarbolifecoach", 
 "NorthStarMarket", 
 "marshawright", 
 "Inc", 
 "bigskyrise", 
 "cindyannhealer", 
 "BrettRoryThomas", 
 "FrugalFitEbooks", 
 "Arnaud3J", 
 "ChrisPercival_", 
 "marshawright", 
 "StefanHeineken", 
 "lovenregards", 
 "Qualtrics", 
 "j_ramos23", 
 "GrantCardone", 
 "mamoonline101", 
 "donadosays", 
 "Amiltone_", 
 "ChrisPercival_", 
 "ChrisPercival_", 
 "tinybuddha", 
 "Deep_nepalinfo", 
 "CoastalDeb", 
 "NightingaleEarl", 
 "ChrisPercival_", 
 "joshelledge", 
 "Deep_nepalinfo", 
 "Deep_nepalinfo", 
 "Anvesh_Marri", 
 "LoriMoreno", 
 "LoriMoreno", 
 "theRealKiyosaki", 
 "Deep_nepalinfo", 
 "Deep_nepalinfo", 
 "naichicarpeso", 
 "lulusync", 
 "gamechangerszim", 
 "VeganYogaDude", 
 "Mazars_UK", 
 "gamechangerszim", 
 "joshelledge", 
 "Deep_nepalinfo", 
 "Deep_nepalinfo", 
 "LeadToday", 
 "HaroldSinnott", 
 "LeadToday", 
 "MicheleRuiz01", 
 "LoriMoreno", 
 "LoriMoreno", 
 "CompeteEveryDay", 
 "HPYoungVoices", 
 "_drudgereport_", 
 "Russper", 
 "Deep_nepalinfo", 
 "Deep_nepalinfo", 
 "VeganYogaDude", 
 "ElisaBBennett", 
 "_GarethG", 
 "AurorasaCoach", 
 "TheZigZiglar", 
 "milindrunning", 
 "DerekLidow", 
 "HarvardBiz", 
 "danspena", 
 "inc5000", 
 "ahhensel", 
 "marshawright", 
 "_GarethG", 
 "_GarethG", 
 "marshawright", 
 "bigskyrise", 
 "Deep_nepalinfo", 
 "_GarethG", 
 "Deep_nepalinfo", 
 "TheDaveKirby", 
 "OfficialJimRohn", 
 "DCTheState", 
 "nikproffitt", 
 "SteveGutzler", 
 "LoriMoreno", 
 "LoriMoreno", 
 "GBGunderson", 
 "PatriciaMavinyu", 
 "Deep_nepalinfo", 
 "InspirEmerge", 
 "Deep_nepalinfo", 
 "1andreacallahan", 
 "TheDennisWagner", 
 "BeltwayPundit", 
 "PatriciaMavinyu", 
 "devinetaylor", 
 "marshawright", 
 "ilovefairchoice", 
 "LoriMoreno", 
 "LoriMoreno", 
 "SavvyHustlers", 
 "marshawright", 
 "LoriMoreno", 
 "Ironmanjack", 
 "SteveGutzler", 
 "marshawright", 
 "SavvyHustlers", 
 "CompeteEveryDay", 
 "DaviesWriter", 
 "SavvyHustlers", 
 "Ziko_3D", 
 "Inc", 
 "addmefastwwwim", 
 "TheZigZiglar", 
 "QueenBDivine", 
 "nowyvr", 
 "nickwriteastory", 
 "TheChampsView", 
 "charlesjo", 
 "paleofuture", 
 "Gizmodo", 
 "ssgslack", 
 "romeabout", 
 "VeganYogaDude", 
 "COUTSIFROMWEST", 
 "VeganYogaDude", 
 "addmefastwwwim", 
 "LoriMoreno", 
 "cheri_shapley", 
 "TechGeekRebel", 
 "ericomuro", 
 "VeganYogaDude", 
 "NorthStarMarket", 
 "mlmtips_edu", 
 "SavvyCleaner", 
 "TheArtofCharm", 
 "SavvyCleaner", 
 "gajo4all", 
 "SeffSaid", 
 "GriffIzMe", 
 "TheZigZiglar", 
 "5onlife", 
 "Bailey_Boutique", 
 "StartGrowthHack", 
 "CoachBrettBlair", 
 "Plansmith", 
 "darren_flow", 
 "asalesguy", 
 "TheArtofCharm", 
 "SavvyCleaner", 
 "PorcelliSuzanne", 
 "KariJoys", 
 "TheDennisWagner", 
 "NorthStarMarket", 
 "NorthStarMarket"
]

Example 8. Using prettytable to display tuples in a nice tabular format


In [26]:
from prettytable import PrettyTable

for label, data in (('Word', words), 
                    ('Screen Name', screen_names), 
                    ('Hashtag', hashtags)):
    pt = PrettyTable(field_names=[label, 'Count']) 
    c = Counter(data)
    [ pt.add_row(kv) for kv in c.most_common()[:10] ]
    pt.align[label], pt.align['Count'] = 'l', 'r' # Set column alignment
    print pt


+-------------+-------+
| Word        | Count |
+-------------+-------+
| #success    |   246 |
| RT          |   142 |
| to          |   123 |
| #Success    |   109 |
| you         |    84 |
| the         |    83 |
| is          |    68 |
| a           |    57 |
| #motivation |    55 |
| #quote      |    53 |
+-------------+-------+
+-----------------+-------+
| Screen Name     | Count |
+-----------------+-------+
| marshawright    |    14 |
| LoriMoreno      |    14 |
| Deep_nepalinfo  |    13 |
| VeganYogaDude   |     9 |
| ChrisPercival_  |     8 |
| TheZigZiglar    |     5 |
| _GarethG        |     4 |
| NorthStarMarket |     4 |
| GeorgeGEdwards  |     4 |
| SavvyCleaner    |     3 |
+-----------------+-------+
+-----------------+-------+
| Hashtag         | Count |
+-----------------+-------+
| success         |   260 |
| Success         |   114 |
| motivation      |    63 |
| quote           |    53 |
| entrepreneur    |    32 |
| Entrepreneur    |    30 |
| defstar5        |    29 |
| Startup         |    28 |
| MakeYourOwnLane |    25 |
| mpgvip          |    25 |
+-----------------+-------+

Example 9. Calculating lexical diversity for tweets


In [27]:
# A function for computing lexical diversity
def lexical_diversity(tokens):
    return 1.0*len(set(tokens))/len(tokens) 

# A function for computing the average number of words per tweet
def average_words(statuses):
    total_words = sum([ len(s.split()) for s in statuses ]) 
    return 1.0*total_words/len(statuses)

print lexical_diversity(words)
print lexical_diversity(screen_names)
print lexical_diversity(hashtags)
print average_words(status_texts)


0.403192934783
0.576354679803
0.274011299435
14.9063291139

In [30]:
retweets = [
            # Store out a tuple of these three values ...
            (status['retweet_count'], 
             status['retweeted_status']['user']['screen_name'],
             status['text'],
             status['retweeted_status']['id']
            ) 
            
            # ... for each status ...
            for status in statuses            
            # ... so long as the status meets this condition.
                if status.has_key('retweeted_status')
                    
           ]

# Slice off the first 5 from the sorted results and display each item in the tuple

pt = PrettyTable(field_names=['Count', 'Screen Name', 'Text', 'id'])
[ pt.add_row(row) for row in sorted(retweets, reverse=True)[:5] ]
pt.max_width['Text'] = 50
pt.align= 'l'
print pt


+-------+---------------+----------------------------------------------------+--------------------+
| Count | Screen Name   | Text                                               | id                 |
+-------+---------------+----------------------------------------------------+--------------------+
| 249   | VeganYogaDude | RT @VeganYogaDude: This! Do this! And have a great | 833667112648466436 |
|       |               | week                                               |                    |
|       |               | #mondaymotivation #Startup #Success                |                    |
|       |               | #MakeYourOwnLane #defstar5 #mpgvip #inspiration…   |                    |
| 249   | VeganYogaDude | RT @VeganYogaDude: This! Do this! And have a great | 833667112648466436 |
|       |               | week                                               |                    |
|       |               | #mondaymotivation #Startup #Success                |                    |
|       |               | #MakeYourOwnLane #defstar5 #mpgvip #inspiration…   |                    |
| 249   | VeganYogaDude | RT @VeganYogaDude: This! Do this! And have a great | 833667112648466436 |
|       |               | week                                               |                    |
|       |               | #mondaymotivation #Startup #Success                |                    |
|       |               | #MakeYourOwnLane #defstar5 #mpgvip #inspiration…   |                    |
| 249   | VeganYogaDude | RT @VeganYogaDude: This! Do this! And have a great | 833667112648466436 |
|       |               | week                                               |                    |
|       |               | #mondaymotivation #Startup #Success                |                    |
|       |               | #MakeYourOwnLane #defstar5 #mpgvip #inspiration…   |                    |
| 249   | VeganYogaDude | RT @VeganYogaDude: This! Do this! And have a great | 833667112648466436 |
|       |               | week                                               |                    |
|       |               | #mondaymotivation #Startup #Success                |                    |
|       |               | #MakeYourOwnLane #defstar5 #mpgvip #inspiration…   |                    |
+-------+---------------+----------------------------------------------------+--------------------+

Example 11. Looking up users who have retweeted a status


In [31]:
# Get the original tweet id for a tweet from its retweeted_status node 
# and insert it here in place of the sample value that is provided
# from the text of the book

_retweets = twitter_api.statuses.retweets(id=833667112648466436)
print [r['user']['screen_name'] for r in _retweets]


[u'WatchEm_FoldUp', u'yung_580', u'collinsturner47', u'WALKIN_ZAN', u'LoveLightOn', u'DanGlover1', u'AvonUKBeABoss', u'GemiiFromDaBx', u'readershealth', u'JehovahWord777', u'eangels1064', u'jassit5', u'DebraKAdamsMA', u'friendlyWendyB', u'DianaLucia_NS', u'AlphaDeltaHC', u'ShySheppy', u'Psycc0daSpartan', u'marytennant0814', u'NatashaRaynerz']

Example 12. Plotting frequencies of words


In [39]:
%matplotlib inline

import matplotlib
import numpy as np
import matplotlib.pyplot as plt

word_counts = sorted(Counter(words).values(), reverse=True)

plt.loglog(word_counts)
plt.ylabel("Freq")
plt.xlabel("Word Rank")


Out[39]:
<matplotlib.text.Text at 0x7fb7e66fd390>

Example 13. Generating histograms of words, screen names, and hashtags


In [40]:
for label, data in (('Words', words), 
                    ('Screen Names', screen_names), 
                    ('Hashtags', hashtags)):

    # Build a frequency map for each set of data
    # and plot the values
    c = Counter(data)
    plt.hist(c.values())
    
    # Add a title and y-label ...
    plt.title(label)
    plt.ylabel("Number of items in bin")
    plt.xlabel("Bins (number of times an item appeared)")
    
    # ... and display as a new figure
    plt.figure()


<matplotlib.figure.Figure at 0x7fb7e633d110>

Example 14. Generating a histogram of retweet counts


In [53]:
# Using underscores while unpacking values in
# a tuple is idiomatic for discarding them
counts = []

for status in statuses:
    counts.append(status['retweet_count'])
#counts = [count for count, _, _ in retweets]

plt.hist(counts)
plt.title("Retweets with 0")
plt.xlabel('Bins (number of times retweeted)')
plt.ylabel('Number of tweets in bin')


Out[53]:
<matplotlib.text.Text at 0x7fb7e5f5e4d0>

In [56]:
counts = []
for status in statuses:
    if status['retweet_count'] > 0:
        counts.append(status['retweet_count'])
plt.hist(counts)
plt.title("Retweets with 0")
plt.xlabel('Bins (number of times retweeted)')
plt.ylabel('Number of tweets in bin')


Out[56]:
<matplotlib.text.Text at 0x7fb7e6024fd0>

Note: This histogram gives you an idea of how many times tweets are retweeted with the x-axis defining partitions for tweets that have been retweeted some number of times and the y-axis telling you how many tweets fell into each bin. For example, a y-axis value of 5 for the "15-20 bin" on the x-axis means that there were 5 tweets that were retweeted between 15 and 20 times.

Here's another variation that transforms the data using the (automatically imported from numpy) log function in order to improve the resolution of the plot.


In [65]:
# Using underscores while unpacking values in
# a tuple is idiomatic for discarding them

counts = []
for status in statuses:
    if status['retweet_count'] > 0:
        counts.append(math.log(status['retweet_count']))

# Taking the log of the *data values* themselves can 
# often provide quick and valuable insight into the
# underlying distribution as well. Try it back on
# Example 13 and see if it helps.

plt.hist((counts))
plt.title("Retweets")
plt.xlabel('Log[Bins (number of times retweeted)]')
plt.ylabel('Log[Number of tweets in bin]')

print log(counts)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-65-be11203e74e1> in <module>()
     17 plt.ylabel('Log[Number of tweets in bin]')
     18 
---> 19 print log(counts)

NameError: name 'log' is not defined

In [ ]: